using System;
using System.Collections.Generic;
using System.Text;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data;

namespace DataAccessLayer
{
    public class Disease
    {
        private string DiseaseName;
        private string Specialization;
        private string Description;
        private string connstring;
        
        public Disease(string connstring)
        {
            this.connstring = connstring;
        }
        public string DNAME
        {
            get { return DiseaseName; }
            set { DiseaseName = value; }
        }
        public string SPL
        {
            get { return Specialization; }
            set { Specialization = value; }
        }
        public string DESCRP
        {
            get { return Description; }
            set { Description = value; }
        }
        public DataTable show()
        {
            SqlDataReader s1 = null;
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "show";
            cmd.CommandType = CommandType.StoredProcedure;
            s1 = cmd.ExecuteReader();
            DataTable dtDisplay = new DataTable();
            dtDisplay.Load(s1);
            con.Close();
            return dtDisplay;
        }
        public int desiseaseVerification(string desname)
        {
            int k = 0;
            SqlConnection objCon = new SqlConnection(connstring);
            objCon.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = objCon;
            cmd.CommandText = "sp_seacrh_disease";
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ds.Clear();
            da.Fill(ds);
            int i = ds.Tables[0].Rows.Count;

            for (int j = 0; j < i; j++)
            {
                if (DiseaseName == ds.Tables[0].Rows[j][0].ToString())
                {
                    k = 1;
                    break;
                }
            }
            return k;
        }
        public int addDisease()
        {
            SqlConnection con = new SqlConnection(connstring);
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "sp_add_disease";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@Dname", DiseaseName));
            cmd.Parameters.Add(new SqlParameter("@Splc", Specialization));
            cmd.Parameters.Add(new SqlParameter("@Desp", Description));

            int noOfRows = cmd.ExecuteNonQuery();
            con.Close();
            return noOfRows;
        }
    }
}
